<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>会员资料-{$coreVersion}</title>
    {template 'stourtravel/public/public_js'}
    {php echo Common::getCss('style.css,base.css,base2.css,member-info.css,base_new.css'); }
    {php echo Common::getScript("choose.js"); }
</head>
<body>
<input type="hidden" name="mid" value="{$mid}" >

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td">

            <div class="cfg-header-bar">
                {template 'stourtravel/public/member_top'}
            </div>
            <div class="cfg-header-bar" style="background: white;">
                <div class="cfg-header-order-info">
                    <div class="fl select-box w100 mt-3 ml-10">
                        <select name="source" data-fieldname="type" onchange="togStatusChange(this)" class="select">
                            <option value="">全部积分</option>
                            <option value="2">获得积分</option>
                            <option value="1">消费积分</option>
                        </select>
                    </div>
                    <span class="item">总获得积分：<span id="today_price" class="c-orange">{$user_info['jifen_get_all']}</span></span>
                    <span class="item">消费积分：<span id="last_price" class="c-orange">{$user_info['jifen_used_all']}</span></span>
                    <span class="item">剩余积分：<span id="thisweek_price" class="c-orange">{$user_info['jifen']}</span></span>
                    <a href="javascript:;" id="addbtn" class="fr btn btn-primary radius mt-6 mr-10" title="添加" style="margin-left: 100px;">赠送积分</a>
                    <a href="javascript:;" id="subbtn" class="fr btn btn-primary radius mt-6 mr-10" title="减少" style="margin-left: 100px;">减少积分</a>
                </div>
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
            </div>
            <div id="product_grid_panel" class="content-nrt" >

            </div>
        </td>
    </tr>
</table>




</body>
</html>

<script>
    $(function () {
        var mid = $("input[name='mid']").val();
        //添加按钮
        $("#addbtn").click(function(){
            var url=SITEURL+"member/add_jifen/mid/"+mid+'/type/2';
            ST.Util.showBox('赠送积分',url,420,200,function(){window.product_store.load()});
        });
        //减少按钮
        $("#subbtn").click(function(){
            var url=SITEURL+"member/add_jifen/mid/"+mid+'/type/1';
            ST.Util.showBox('减少积分',url,420,200,function(){window.product_store.load()});
        });

    });
    window.display_mode = 1;	//默认显示模式
    window.product_kindid = 0;  //默认目的地ID


    window.statusmenu={json_encode($statusnames)};
    window.paysources={json_encode($paysources)};


    Ext.onReady(
        function () {
            Ext.tip.QuickTipManager.init();
            //var editico = "{php echo Common::getIco('edit');}";
            var delico = "{php echo Common::getIco('del');}";
            var editico = "{php echo Common::getIco('order');}";
            var unviewico="{php echo Common::getIco('order_unview');}";
            $("#searchkey").focusEffect();


            //产品store
            window.product_store = Ext.create('Ext.data.Store', {
                fields: [
                    'id',
                    'typeMsg',
                    'type',
                    'memberid',
                    'jifen',
                    'content',
                    'addtime'
                ],
                proxy: {
                    type: 'ajax',
                    api: {
                        read: SITEURL+"member/jifen_list/mid/{$mid}/act/read/",  //读取数据的URL
                        update: SITEURL+"member/jifen_list/mid/{$mid}/act/save/",
                        destroy: SITEURL+"member/jifen_list/mid/{$mid}/act/delete/"
                    },
                    reader: {
                        type: 'json',   //获取数据的格式
                        root: 'list',
                        totalProperty: 'total'
                    }
                },
                remoteSort: true,
                pageSize: 15,
                autoLoad: true,
                listeners: {
                    load: function (store, records, successful, eOpts) {
                        if(!successful){
                            ST.Util.showMsg("{__('norightmsg')}",5,1000);
                        }
                        var pageHtml=ST.Util.page(store.pageSize,store.currentPage,store.getTotalCount(),10);
                        $("#line_page").html(pageHtml);
                        window.product_grid.doLayout();
                        $(".pageContainer .pagePart a").click(function () {
                            var page = $(this).attr('page');
                            product_store.loadPage(page);
                        });

                    }
                }

            });

            //产品列表
            window.product_grid = Ext.create('Ext.grid.Panel', {
                store: product_store,
                renderTo: 'product_grid_panel',
                border: 0,
                width: "100%",
                bodyBorder: 0,
                bodyStyle: 'border-width:0px',
                scroll:'vertical', //只要垂直滚动条
                bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "",
                    items: [
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                        },
                        {
                            xtype: 'combo',
                            fieldLabel: '每页显示数量',
                            width: 170,
                            labelAlign: 'right',
                            forceSelection: true,
                            value: 15,
                            store: {fields: ['num'], data: [
                                {num: 15},
                                {num: 30},
                                {num: 50}
                            ]},
                            displayField: 'num',
                            valueField: 'num',
                            listeners: {
                                select: changeNum
                            }
                        }

                    ],

                    listeners: {
                        single: true,
                        render: function (bar) {
                            var items = this.items;
                            //  bar.down('tbfill').hide();

//                            bar.insert(0, Ext.create('Ext.panel.Panel',
//                                {
//                                    border: 0,
//                                    html: '<div class="panel_bar"><a class="btn btn-primary radius" href="javascript:void(0);" onclick="CHOOSE.chooseAll()">全选</a>'+
//                                    '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.chooseDiff()">反选</a>'+
//                                    '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.viewAll(selecteViewed)">已读</a>'+
//                                    '<a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="CHOOSE.delorderMore()">删除</a></div>'
//                                }
//                                )
//                            );
                            bar.insert(0, Ext.create('Ext.toolbar.Fill'));
                        }
                    }
                }),
                columns: [
                    {
                        text: '日期',
                        width: '30%',
                        dataIndex: 'addtime',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;
                        }

                    },

                    {
                        text: '内容说明',
                        width: '45%',
                        dataIndex: 'content',
                        align: 'left',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            return value;
                        }

                    },
                    {
                        text: '分值',
                        width: '25%',
                        dataIndex: 'jifen',
                        align: 'center',
                        border: 0,
                        sortable: false,
                        menuDisabled:true,
                        renderer: function (value, metadata, record) {
                            var id=record.get('id');
                            var type=record.get('type');
                            if(value && value>0) {
                                var color=type==2?'green':'red';
                                return '<span style="color:'+color+'">'+ (type==2?'+':'-') + value + '</span>';
                            }
                            return value;
                        }

                    }
                ],
                listeners: {
                    boxready: function () {
                        var height = Ext.dom.Element.getViewportHeight();
                        this.maxHeight = height-76 ;
                        this.doLayout();
                    },
                    afterlayout: function (grid) {
//                        var data_height = 0;
//                        try {
//                            data_height = grid.getView().getEl().down('.x-grid-table').getHeight();
//                        } catch (e) {
//
//                        }
//                        var height = Ext.dom.Element.getViewportHeight();
//                        console.log(data_height + '---' + height);
//                        if (data_height > height - 76) {
//                            window.has_biged = true;
//                            grid.height = height - 76;
//                        }
//                        else if (data_height < height - 76) {
//                            if (window.has_biged) {
//                                delete window.grid.height;
//                                window.has_biged = false;
//                                grid.doLayout();
//                            }
//                        }
                    }
                },
                plugins: [
                    Ext.create('Ext.grid.plugin.CellEditing', {
                        clicksToEdit: 2,
                        listeners: {
                            edit: function (editor, e) {
                                var id = e.record.get('mid');
                                //  var view_el=window.product_grid.getView().getEl();
                                //  view_el.scrollBy(0,this.scroll_top,false);
                                updateField(0, id, e.field, e.value, 0);
                                return false;

                            }

                        }
                    })
                ],
                viewConfig: {
                    enableTextSelection:true
                }
            });


        })

    //实现动态窗口大小
    Ext.EventManager.onWindowResize(function () {

        var height = Ext.dom.Element.getViewportHeight();
        var data_height = window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
        if (data_height > height - 76)
            window.product_grid.height = (height - 76);
        else
            delete window.product_grid.height;
        window.product_grid.doLayout();


    })


    function selecteViewed(ids){
        Ext.Ajax.request({
            url   :  SITEURL+"order/viewed",
            method  :  "POST",
            datatype  :  "JSON",
            params:{ids:ids.join(',')},
            success  :  function(response, opts)
            {
                if(response.responseText=='ok')
                {
                    var record;
                    $.each(ids,function(index,value){
                        record=window.product_store.getById(value.toString());
                        record.set('viewstatus',1);
                        record.commit();
                    });
                }
                else
                {
                    ST.Util.showMsg("{__('norightmsg')}",5,1000);
                }
            }
        });
    }

    /**
     * 状态改变
     * @param ele
     */
    function togStatusChange(ele){
        var v=$(ele).val();
        var fieldname = $(ele).data('fieldname');

        window.product_store.getProxy().setExtraParam(fieldname,v);
        window.product_store.loadPage(1);

    }
    //查看实名信息
    function toShowVerify(id)
    {
        var url=SITEURL+"member/verifystatus_list/action/show/parentkey/member/menuid/{$meunid}/itemid/1/mid/"+id;
       // var record=window.product_store.getById(id.toString());
        parent.window.addTab('实名认证详情',url,1);
    }

    //查看导游信息
    function toShowGuide(id)
    {
        var url=SITEURL+"guide/admin/guide/info/id/"+id+"/menuid/{$guide_menuid}/";
        parent.window.addTab('实名认证详情',url,1);
    }
    $(function()
    {

        YYYYMMDDstart();
        var year =  '{$info['birth_date'][0]}';
        var month =  '{$info['birth_date'][1]}';
        var day =  '{$info['birth_date'][2]}';
        if(year)
        {
            $('select[name=bairth_year]').val(year);
        }
        if(month)
        {
            month = parseInt(month);
            var n = MonHead[month-1];
            if (month==2&&IsPinYear(year)==true)
            {
                n++;
            }
            writeDay(n);
            $('select[name=bairth_month]').val(month);
        }
        if(day)
        {
            day = parseInt(day)
            $('select[name=bairth_day]').val(day);
        }

        var constellation = '{$info['constellation']}';
        $('select[name=constellation]').val(constellation);//星座选中
        //密码重置,8位随机密码
        $('#default-pwd').click(function()
        {
            var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
            var maxPos = chars.length;
            var pwd = '';
            for (i = 0; i < 8; i++) {
                pwd += chars.charAt(Math.floor(Math.random() * maxPos));
            }
            $('input[name=password]').val(pwd)
        })

        //提交
        $('#save_btn').click(function()
        {
            var pwd =  $('input[name=password]').val();
            if(pwd)
            {
                ST.Util.confirmBox("提示","确定要重置密码？",function(){
                    submit_frm();
                })
            }
            else
            {
                submit_frm();
            }

        })
    });


    //提交
    function submit_frm()
    {
        $.ajax({
            type:'post',
            dataType:'json',
            url:SITEURL+'member/ajax_save',
            data:$('#frm').serialize(),
            success:function(data)
            {
                if(data.status)
                {
                    ST.Util.showMsg('保存成功!','4',2000);
                }
                else
                {
                    ST.Util.showMsg('保存失败!','5',2000);
                }

            }

        })

    }

    function YYYYMMDDstart()
    {
        MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        //先给年下拉框赋内容
        var y = new Date().getFullYear();
        for (var i = (y - 100); i <= y ; i++) //以今年为准，前100年
        {
            $('select[name=bairth_year]').append(new Option(" " + i + " 年", i));
        }
        //赋月份的下拉框
        for (var i = 1; i < 13; i++)
        {
            $('select[name=bairth_month]').append(new Option(" " + i + " 月", i));
        }
    }
    //切换每页显示数量
    function changeNum(combo, records) {
        var pagesize=records[0].get('num');
        window.product_store.pageSize=pagesize;
        window.product_store.loadPage(1);
    }

    if (document.attachEvent)
    {
        window.attachEvent("onload", YYYYMMDDstart);
    }
    else
    {
        window.addEventListener('load', YYYYMMDDstart, false);
    }

    function YYYYDD(year) //年发生变化时日期发生变化(主要是判断闰平年)
    {
        $('select[name=bairth_month]').attr('year',year);
        $('select[name=bairth_month]').val(0);
        $('select[name=bairth_day]').val(0);
    }
    function MMDD(month,obj) //月发生变化时日期联动
    {
        $('select[name=bairth_day]').val(0);
        var n = MonHead[month-1];
        var year = $(obj).attr('year');
        if (month==2&&IsPinYear(year)==true)
        {
            n++;
        }
        writeDay(n);
    }
    function writeDay(n) //据条件写日期的下拉框
    {
        var html = '<option value="0">请选择日</option>';
        for (var i = 1; i < (n + 1); i++)
        {
            html +='<option value="'+i+'">'+i+'日</option>'
        }
        $('select[name=bairth_day]').html(html);
    }

    function IsPinYear(year) //判断是否闰平年
    {
        return (0 == year % 4 && (year % 100 != 0 || year % 400 == 0));
    }



</script>